#include"Contact.h"
void ListInit(Contact** ppcon)
{
	*ppcon = NULL;
}
Contact* ListBuyNode(DataType x)
{
	Contact* newnode = (Contact*)malloc(sizeof(Contact));
	if (newnode == NULL)
	{
		perror("malloc fail!");
		exit(1);
	}
	newnode->data = x;
	newnode->next = NULL;
	return newnode;
}
void ListPushBack(Contact** ppcon, DataType x)
{
	assert(ppcon);
	Contact* newnode = ListBuyNode(x);
	if (*ppcon == NULL)
	{
		*ppcon = newnode;
	}
	else
	{
		Contact* ptail = *ppcon;
		while (ptail->next != NULL)
		{
			ptail = ptail->next;
		}
		ptail->next = newnode;
	}
}

void ListErase(Contact** ppcon, Contact** pos)
{
	assert(ppcon && *ppcon && *pos);
	if (*pos == *ppcon)
	{
		Contact* newpcon = (*ppcon)->next;
		free(*ppcon);
		*ppcon = newpcon;
	}
	else {
		Contact* prev = *ppcon;
		while (prev->next != *pos)
		{
			prev = prev->next;
		}
		prev->next = (*pos)->next;
		free(*pos);
	}
}